package com.yxdj.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxdj.service.api.domain.ServiceItem;
import com.yxdj.service.mapper.ServiceItemMapper;
import com.yxdj.service.mapper.SubCategoryMapper;
import com.yxdj.service.service.ServiceItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
* @author 韩总
* @description 针对表【service_item(服务项目表)】的数据库操作Service实现
* @createDate 2025-03-20 14:44:40
*/
@Service
public class ServiceItemServiceImpl extends ServiceImpl<ServiceItemMapper, ServiceItem>
    implements ServiceItemService{

    @Autowired
    private SubCategoryMapper subCategoryMapper;

    @Override
    public List<ServiceItem> getPageList(ServiceItem serviceItem) {
        LambdaQueryWrapper<ServiceItem> serviceItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
        serviceItemLambdaQueryWrapper.like(serviceItem.getServiceName() != null, ServiceItem::getServiceName, serviceItem.getServiceName());
        List<ServiceItem> serviceItems = baseMapper.selectList(serviceItemLambdaQueryWrapper);
        if(!CollectionUtils.isEmpty(serviceItems)){
            for (ServiceItem serviceItem1 : serviceItems) {
                serviceItem1.setSubCategoryName(subCategoryMapper.selectById(serviceItem1.getSubCategoryId()).getSubCategoryName());
            }
        }
        return serviceItems;
    }
}




